//顺序表的底层就是 数组

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class ArrayListTest {


    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        Iterator<Integer> iterator= arrayList.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next() + " ");
        }

        Iterator<Integer> iterator1 = arrayList.listIterator();
        while (iterator1.hasNext()){
            System.out.println(iterator1.next() + " ");
        }

        List<Integer> list = new ArrayList<>();

    }


    public static void main5(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(10);
        arrayList.add(12);
        arrayList.add(23);
        arrayList.add(34);
        System.out.println(arrayList);
        System.out.println("======");

//        for (int i = 0; i < arrayList.size(); i++) {
//            System.out.println(arrayList.get(i) + " ");
//        }

        //foreach打印
        System.out.println("foreach打印");
        for (Integer x:arrayList) {
            System.out.println(x + " ");
        }

//        for(Integer x : arrayList){
//            System.out.println();
//        }
//
//        for(Integer x : arrayList) {
//            System.out.println();
//        }

//          for(Integer x: arrayList){
//
//          }


//
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i)+" ");
        }
        System.out.println();
        System.out.println("======");

        for(Integer x : arrayList) {
            System.out.print(x+" ");
        }
        System.out.println();
        System.out.println("===iterator===");
        //默认是从 0 下标开始打印
        Iterator<Integer> it =  arrayList.iterator();
        while (it.hasNext()) {
            System.out.print(it.next() +" ");
        }
        System.out.println();
        System.out.println("===ListIterator===");

        Iterator<Integer> it0000 = arrayList.iterator();

        ListIterator<Integer> it2 =  arrayList.listIterator();
        while (it2.hasNext()) {
            System.out.print(it2.next() +" ");
        }
        System.out.println();
        System.out.println("===listIterator 倒着打印===");
        //从 指定位置 开始打印     arrayList.size()
        ListIterator<Integer> it3 =  arrayList.listIterator(arrayList.size());

        while (it3.hasPrevious()) {
            System.out.print(it3.previous() +" ");
        }
        System.out.println();
        System.out.println("======");
    }


    public static void main4(String[] args) {

        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1110);
        arrayList.add(2220);
        arrayList.add(3330);
        arrayList.add(4440);
        System.out.println(arrayList);

        //sublist方法 的返回值是 还是原数组的地址
        List<Integer> list = arrayList.subList(0,2);
        System.out.println(list);

        //因此此处 list的值修改了之后，arraylist的值也被修改了
        list.set(1,99);
        System.out.println(list);
        System.out.println();
        System.out.println(arrayList);
    }

    public static void main3(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(10);
        arrayList.add(12);
        arrayList.add(23);
        arrayList.add(34);
        System.out.println(arrayList);

        List<Integer> list = arrayList.subList(1,3);
        //sublist范围是 前闭后开
        System.out.println(list);

        list.set(0,99);
        System.out.println(list);
        System.out.println("=======");
        System.out.println(arrayList);
    }

    public static void main2(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(12);
        arrayList.add(12);
        arrayList.add(23);
        arrayList.add(23);
        arrayList.add(34);
        arrayList.add(34);
        System.out.println(arrayList);

        //删除指定数字
        arrayList.remove(Integer.valueOf(12));
        System.out.println(arrayList);

        arrayList.remove(Integer.valueOf(12));
        System.out.println(arrayList);

        //删除1下标的数字
        arrayList.remove(1);
        System.out.println(arrayList);

        //删除所有
        arrayList.removeAll(arrayList);
        System.out.println(arrayList);
    }





    //顺序表的底层就是 数组
    public static void main1(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();

        arrayList.add(12);
        arrayList.add(34);
        arrayList.add(45);
        arrayList.add(1,99);
        System.out.println(arrayList);

        System.out.println();
        List<Integer> list = new ArrayList<>();


        list.add(12);
        list.add(34);
        list.add(45);
        list.add(2,99);
        System.out.println(list);


        ArrayList<Integer> arrayList1 = new ArrayList<>();
        ArrayList<Integer> arrayList2 = new ArrayList<>(20);

        //一次性将整个 arraylist 放入 arraylist1
        arrayList1.addAll(arrayList);
        System.out.println(arrayList1);

    }
}
